using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace Gobang
{
    public class PredictionPoint : MonoBehaviour
    {
        public Color color_best;
        public Color color_normal;
        public Color color_uncertain;

        public int threshold_visible;
        public int threshold_uncertain;

        private Image image;
        private TextMeshProUGUI tmp;

        public void Initialize(PredictionPointData data)
        {
            if(data.mockTimes > threshold_visible)
            {
                if (data.sortingValue == 1)
                    image.color = color_best;
                else
                    image.color = data.mockTimes < threshold_uncertain ? color_uncertain : color_normal;
                tmp.text = $"{data.sortingValue}\n" +
                        $"{data.winTimes / data.mockTimes:P1}\n" +
                        $"{ChessboardUtility.FormatMockTimes(data.mockTimes)}";
            }
            else
            {
                image.color = Color.clear;
                tmp.text = string.Empty;
            }
        }

        private void Awake()
        {
            image = GetComponentInChildren<Image>();
            tmp = GetComponentInChildren<TextMeshProUGUI>();
        }
    }
}